﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Data.SQLite;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using _4m.Utils;
using _4m.forms;
using _4m.utils;

namespace _4m
{
    public partial class mainForm : Form
    {
        private DirPickerForm dirPickerForm;

        public mainForm()
        {
            if (File.Exists(Constants.SqliteConnString))
            {
                Debug.WriteLineIf(Constants.Debug, string.Format("删除文件：{0}", Constants.SqliteConnString));
                File.Delete(Constants.SqliteConnString);
            }

            string connStr = SQLiteUtils.GetConnectionString(Constants.SqliteConnString);
            var sqliteUtils = new SQLiteUtils();
            bool flag = sqliteUtils.TestConnect(connStr);
            Debug.WriteLineIf(Constants.Debug, string.Format("数据库连接状态：{0}", flag));

            // 清理数据库用表
            sqliteUtils.ExecuteUpdate(SQLConstants.DeleteTableOnWeek, connStr);
            sqliteUtils.ExecuteUpdate(SQLConstants.DeleteTableOnRange, connStr);

            // 创建数据库用表
            sqliteUtils.ExecuteUpdate(SQLConstants.CreateTableOnWeek, connStr);
            sqliteUtils.ExecuteUpdate(SQLConstants.CreateTableOnRange, connStr);
            
            if (this.dirPickerForm == null)
            {
                this.dirPickerForm = new DirPickerForm();
            }
            InitializeComponent();
            
            //var ds = ExcelUtils.LoadDataFromExcel("F:\\backup\\工作相关\\代码文件\\文档\\4m\\10年与11年按周按病种发病分析图.xls", "手足口病");
        }

        /// <summary>
        /// 显示“关于”对话框
        /// </summary>
        private void MenuItemAboutClick(object sender, EventArgs e)
        {
            var aboutBox = new AboutBox();
            aboutBox.ShowDialog();
        }

        /// <summary>
        /// 目录选择对话框
        /// </summary>
        private void MenuItemDirPickerClick(object sender, EventArgs e)
        {
            dirPickerForm.ShowForm();
            dirPickerForm.ShowDialog();
        }

        /// <summary>
        /// 退出菜单
        /// </summary>
        private void MenuItemExitClick(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}
